package com.example.demo.vo;

import com.example.demo.config.ERHttpStatus;

/**
 * 接口返回类型
 */
public class R {

    // 标识返回的状态
    private Integer code;
    // 返回的数据类型
    private Object data;
    // 返回成功或失败的一个消息
    private String message;

    public R() {
    }

    public R(Integer code, Object data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public static R ok() {
        return new R(200, "", "success");
    }

    /**
     * 成功返回
     * @param data 数据
     * @return R
     */
    public static R ok(Object data) {
        return new R(200, data, "success");
    }

    /**
     * 成功返回
     * @param data 数据
     * @param message 消息
     * @return R
     */
    public static R ok(Object data, String message) {
        return new R(200, data, message);
    }

    public static R error(ERHttpStatus rHttpStatusEnum) {
        return new R(rHttpStatusEnum.code(), "", rHttpStatusEnum.message());
    }

//    public static R error(Integer code, String message) {
//        return new R(code, "", message);
//    }

    public Integer getCode() {
        return code;
    }

    public R code(Integer code) {
        this.code = code;
        return this;
    }

    public Object getData() {
        return data;
    }

    public R data(Object data) {
        this.data = data;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public R message(String message) {
        this.message = message;
        return this;
    }
}
